/**
 * Created by Administrator on 2018/5/31.
 */


var points = [
    {'name':'宝兴县', 'pos':[102.82058,30.388173]},
    {'name':'天全县', 'pos':[102.778663,30.063344]},
    {'name':'荥经县', 'pos':[102.853267,29.799434]},
    {'name':'芦山县', 'pos':[102.939033,30.148236]},
    {'name':'汉源县', 'pos':[102.657688,29.349799]},
    {'name':'石棉县', 'pos':[102.365654,29.234244]},
    {'name':'名山区', 'pos':[103.115734,30.0759]},
    {'name':'雨城区', 'pos':[103.039693,30.011103]}

];

function drawMapCity(id){
    var option = {
        backgroundColor: '#0f0c29', // 0f0c29
        title : { text: '雅安市', left: 'left', textStyle:{color:'#fff'} }, tooltip : { trigger: 'item' },
        legend: {
            orient: 'vertical', top: 'top', left: 'right',
            //data:dts.map(function(d){ return d[0]; }), textStyle: {color: '#000' }
        },
        geo: {
            map: '雅安', label: { normal: { show: true, textStyle: { color: '#05C3F9' } } }, zoom: 1.2, roam: true,
            itemStyle: {
                normal: {
                    color: 'rgba(51, 69, 89, .5)', //地图背景色
                    borderColor: 'rgba(100,149,237,1)' //省市边界线
                },
                emphasis: {
                    color: 'rgba(37, 43, 61, .5)' //悬浮背景
                }
            }
        },
        series: []
    };

    Init3(option, id);
}

function drawBar(id){
    var names = echarts.getMap("雅安").geoJson.features.map(function(d){ return d.properties.name; });
    var data = names.map(function(d){
        return parseInt(Math.random() * 100);
    });
    var option = {
        backgroundColor: '#0f0c29', // rgb(43, 51, 59)
        grid:{ top:'10%' },
        xAxis: {
            data: names,
            axisLine: {
                lineStyle: {
                    color: '#0177d4'
                }
            },
            axisLabel: {
                color: '#fff',
                fontSize: 14,
                interval: 0,
                rotate:45
            }
        },
        yAxis: {
            name: "数量",
            nameTextStyle: {
                color: '#fff',
                fontSize: 16
            },
            axisLine: {
                lineStyle: {
                    color: '#0177d4'
                }
            },
            axisLabel: {
                color: '#fff',
                fontSize: 16
            },
            splitLine: {
                show:false,
                lineStyle: {
                    color: '#0177d4'
                }
            },
            max:150

        },
        series: [{
            type: 'bar',
            barWidth: 18,
            itemStyle:{
                normal:{
                    barBorderRadius: 5,
                    color:new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: '#00b0ff'
                    }, {
                        offset: 0.8,
                        color: '#7052f4'
                    }], false)
                }
            },
            data: data
        }]
    };

    Init3(option ,id);
}

function drawPie(id, title){
    var count = Math.random() * 5 + 5, data = [];
    var colors = ["#f845f1", "#ad46f3", "#5045f6", "#4777f5", "#44aff0", "#45dbf7", "#f6d54a", "#f69846", "#ff4343"];
    data = points.map(function(d, i){
        return {
            name: d.name, value:(Math.random() * 10 + 10).toFixed(2), "itemStyle":
            { "normal": { "color": colors[i] } }
        };
    });

    data.sort(function(a, b){ return a.value - b.value; });
    for(var i=0; i<points.length; i++){
        data.push({
            "value": 0,
            "name": "",
            labelLine:{ show:false },
            label:{ show:false },
            "itemStyle": {
                "normal": {
                    "label": {
                        "show": false
                    },
                    "labelLine": {
                        "show": false
                    }
                }
            }
        });
    }
    var names = data.map(function(d){ return d.name; });
    var option = {
        backgroundColor: '#0f0c29',
        toolbox: {
            show: false,
            feature: {
                mark: {
                    show: true
                },
                dataView: {
                    show: true,
                    readOnly: false
                },
                magicType: {
                    show: true,
                    type: ['pie', 'funnel']
                },
                saveAsImage: {
                    show: true
                }
            }
        },
        calculable: true,
        "tooltip": {
            "trigger": "item",
            "formatter": "{a}<br/>{b}:{c}元"
        },
        "title": {
            "text": title + " 领导班子分布",
            "left": "center",
            "top": 20,
            "textStyle": {
                "color": "#ccc"
            }
        },
        "calculable": true,
        "legend": {
            "icon": "circle",
            "x": "center",
            "y": "15%",
            "data": names,
            "textStyle": {
                "color": "#fff"
            }
        },
        "series": [{
            "name": "XX线索",
            "type": "pie",
            "radius": [
                37,
                155
            ],
            "avoidLabelOverlap": false,
            "startAngle": 0,
            "endAngle": 90,
            "center": [
                "50.1%",
                "34%"
            ],
            "roseType": "area",
            "selectedMode": "single",
            "label": {
                "normal": {
                    "show": true,
                    "formatter": "{c}元"
                },
                "emphasis": {
                    "show": true
                }
            },
            "labelLine": {
                "normal": {
                    "show": true,
                    "smooth": false,
                    "length": 20,
                    "length2": 10
                },
                "emphasis": {
                    "show": true
                }
            },
            "data": data
        }]
    };
    Init3(option, id);
}


function drawBars(id){
    var gain = 0.9;
    var gap = 0;
    var myColor=['#e63810','#ff6b00','#e3b61f','#13b5b1', '#e63810','#ff6b00','#e3b61f','#13b5b1'];
    var myBgColor=['rgba(230,56,16,0.2)','rgba(255,107,0,0.2)','rgba(227,182,31,0.2)','rgba(19,181,177,0.2)',
        'rgba(230,56,16,0.2)','rgba(255,107,0,0.2)','rgba(227,182,31,0.2)','rgba(19,181,177,0.2)'];
    // 柱子数据
    var names = [], cache = {};
    var data = points.map(function(d){ names.push(d.name); return parseInt(Math.random() * 15 + 20); });
    var current = data.map(function(d, i){
        var p = Math.random();
        if(p>0.5)cache[names[i]] = 1;
        return p>0.5 ? d : d - 1 - parseInt(p * 6);
    });
    var option = {
        //backgroundColor:'rgba(0,0,0,0.8)',
        title:{text:'干部数量与职位分布', left:'center', textStyle:{ color:'#fff', fontSize:14 } },
        grid: {
            left: '3%',
            top:'10%',
            right: '2%',
            bottom: '5%',
            containLabel: true
        },
        xAxis: [{
            type: 'category',
            axisTick: {
                show: false
            },
            axisLine:{
                lineStyle:{
                    color:'rgba(160,160,160,0.3)',
                }
            },
            axisLabel:{
                show:true,
                textStyle:{
                    color:function(p){
                        return p in cache ? '#0177d4' : '#f00';
                    },
                    fontSize:13*gain,
                }
            },
            data: names
        }, {
            type: 'category',
            axisLine: {
                show: false
            },
            axisTick: {
                show: false
            },
            axisLabel: {
                show: true
            },
            splitArea: {
                show: false
            },
            splitLine: {
                show: false
            },
            data: []
        },
        ],
        yAxis: {
            type: 'value',
            name:'数量',
            nameGap:35+gap,
            nameTextStyle:{
                color:'#ffffff',
                fontSize:16*gain,
            },
            axisTick: {
                show: false
            },
            axisLine: {
                show: false
            },
            splitLine: {
                lineStyle:{
                    color:'rgba(160,160,160,0.3)',
                }
            },
            axisLabel: {
                textStyle: {
                    color: 'rgba(255,255,255,0.8)',
                    fontSize:14*gain,
                }
            }
        },
        series: [{
            type: 'bar',
            xAxisIndex: 1,
            itemStyle: {
                normal: {
                    show: true,
                    color: function(params) {
                        var num=myBgColor.length;
                        return myBgColor[params.dataIndex%num]
                    },
                    barBorderRadius: 50,
                    borderWidth: 0,
                    borderColor: '#333',
                }
            },
            label:{
                normal:{
                    show:true,
                    formatter: function(p) {
                        var num = data[p.dataIndex] - current[p.dataIndex];
                        return num==0 ? '' : num;
                    },
                    position: 'top',
                    textStyle:{
                        color:'red',
                        fontSize:20 * gain,
                    }
                }
            },
            barWidth: '30%',
            data: data
        },
            {
                type: 'bar',
                itemStyle: {
                    normal: {
                        show: true,
                        color: function(params) {
                            var num=myColor.length;
                            return myColor[params.dataIndex%num]
                        },
                        barBorderRadius: 50,
                        borderWidth: 0,
                        borderColor: '#333',
                    }
                },
                label: {
                    normal: {
                        show: false,
                        rotate:-90,
                        formatter: function(p) { return names[p.dataIndex]; },
                        position:'insideBottom'
                    }
                },
                barWidth: '30%',
                data: current
            }
        ]
    };

    Init3(option, id);

}

function drawData(id){
    var option = {
        series: [
            {
                name: ' 干部总数',
                type: 'pie',
                radius: ['25%', '30%'],
                center: ['30%', '30%'],
                startAngle: 225,
                color: [new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: '#00a2ff'
                }, {
                    offset: 1,
                    color: '#70ffac'
                }]), "transparent"],
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                label: {
                    normal: {
                        position: 'center'
                    }
                },
                data: [{
                    value: 75,
                    name: '干部总数',
                    label: {
                        normal: {
                            formatter: '',
                            textStyle: {
                                color: '#fff',
                                fontSize: 16

                            }
                        }
                    }
                }, {
                    value: 25,
                    name: '%',
                    label: {
                        normal: {
                            formatter: '\n干部总数',
                            textStyle: {
                                color: '#fff',
                                fontSize: 16

                            }
                        }
                    }
                },
                    {
                        value: 0,
                        name: '%',
                        label: {
                            normal: {
                                formatter: '598',
                                textStyle: {
                                    color: '#007ac6',
                                    fontSize: 16

                                }
                            }
                        }
                    }]
            },

            {
                name: ' 班子总数',
                type: 'pie',
                radius: ['25%', '30%'],
                center: ['30%', '70%'],
                startAngle: 225,
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                label: {
                    normal: {
                        position: 'center'
                    }
                },
                data: [{
                    value: 75,
                    "itemStyle": {
                        "normal": {
                            "color": new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                "offset": 0,
                                "color": '#f125ff'
                            }, {
                                "offset": 1,
                                "color": '#2dcbff'
                            }]),
                        }
                    },
                    name: '班子总数',
                    label: {
                        normal: {
                            formatter: '',
                            textStyle: {
                                color: '#fff',
                                fontSize: 16

                            }
                        }
                    }
                }, {
                    value: 25,
                    name: '%',
                    label: {
                        normal: {
                            formatter: '\n班子总数',
                            textStyle: {
                                color: '#fff',
                                fontSize: 16

                            }
                        }
                    }
                },
                    {
                        value: 0,
                        name: '%',
                        label: {
                            normal: {
                                formatter: '64',
                                textStyle: {
                                    color: '#f125ff',
                                    fontSize: 16

                                }
                            }
                        }
                    }]
            },
            {
                type: 'liquidFill',
                radius: '65%',
                center: ['72%', '50%'],
                data: [0.65, 0.55, 0.5, 0.4],
                label: {
                    normal: {
                        formatter: function(){ return '80%'; },
                        // textStyle: {
                        color: 'red',
                        insideColor: 'yellow',
                        fontSize: 50
                        // }
                    }
                }
            }
        ]
    };
    Init3(option, id);
}